<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('purchase:contract:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('purchase:contract:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="序号:">
              <span>{{ props.row.id }}</span>
            </el-form-item>
  <br>
            <el-form-item label="合同编号:">
              <span>{{ props.row.contNum }}</span>
            </el-form-item>
  <br>
            <el-form-item label="买方:">
              <span>{{ props.row.buyer }}</span>
            </el-form-item>
  <br>
            <el-form-item label="卖方:">
              <span>{{ props.row.seller }}</span>
            </el-form-item>
  <br>
            <el-form-item label="供应商编号:">
              <span>{{ props.row.supplierNum }}</span>
            </el-form-item>
  <br>
            <el-form-item label="签定时间:">
              <span>{{ props.row.contDate }}</span>
            </el-form-item>
  <br>
            <el-form-item label="合同类型:">
              <span>{{ props.row.contType }}</span>
            </el-form-item>
  <br>
            <el-form-item label="采购类型:">
              <span>{{ props.row.stockType }}</span>
            </el-form-item>
  <br>
            <el-form-item label="合同标的物:">
              <span>{{ props.row.contItem }}</span>
            </el-form-item>
  <br>
            <el-form-item label="币别:">
              <span>{{ props.row.money }}</span>
            </el-form-item>
  <br>
            <el-form-item label="税率:">
              <span>{{ props.row.taxRate }}</span>
            </el-form-item>
  <br>
            <el-form-item label="包装物是否回收:">
              <span>{{ props.row.wrapBack }}</span>
            </el-form-item>
  <br>
            <el-form-item label="验收标准:">
              <span>{{ props.row.verifyStand }}</span>
            </el-form-item>
  <br>
            <el-form-item label="运输方式:">
              <span>{{ props.row.mode }}</span>
            </el-form-item>
  <br>
            <el-form-item label="付款条件:">
              <span>{{ props.row.payCond }}</span>
            </el-form-item>
  <br>
            <el-form-item label="验收时间:">
              <span>{{ props.row.verifyDate }}</span>
            </el-form-item>
  <br>
            <el-form-item label="质量要求及技术标准:">
              <span>{{ props.row.qualityStand }}</span>
            </el-form-item>
  <br>
            <el-form-item label="标准号:">
              <span>{{ props.row.standardNo }}</span>
            </el-form-item>
  <br>
            <el-form-item label="交(提)货地点:">
              <span>{{ props.row.place }}</span>
            </el-form-item>
  <br>
            <el-form-item label="合同总金额(元):">
              <span>{{ props.row.contPrice }}</span>
            </el-form-item>
  <br>
            <el-form-item label="运输费用负担:">
              <span>{{ props.row.transport }}</span>
            </el-form-item>
  <br>
            <el-form-item label="付款方式:">
              <span>{{ props.row.payWay }}</span>
            </el-form-item>
  <br>
            <el-form-item label="逾期千分比:">
              <span>{{ props.row.outPerm }}</span>
            </el-form-item>
  <br>
            <el-form-item label="逾期天数:">
              <span>{{ props.row.outDay }}</span>
            </el-form-item>
  <br>
            <el-form-item label="备注:">
              <span>{{ props.row.remark }}</span>
            </el-form-item>
  <br>
          </el-form>
        </template>
      </el-table-column>

      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="序号">
      </el-table-column>
      <el-table-column
        prop="contNum"
        header-align="center"
        align="center"
        label="合同编号">
      </el-table-column>
      <el-table-column
        prop="buyer"
        header-align="center"
        align="center"
        label="买方">
      </el-table-column>
      <el-table-column
        prop="seller"
        header-align="center"
        align="center"
        label="卖方">
      </el-table-column>
      <el-table-column
        prop="supplierNum"
        header-align="center"
        align="center"
        label="供应商编号">
      </el-table-column>
      <el-table-column
        prop="contDate"
        header-align="center"
        align="center"
        label="签定时间">
      </el-table-column>
      <el-table-column
        prop="contType"
        header-align="center"
        align="center"
        label="合同类型">
      </el-table-column>
      <el-table-column
        prop="stockType"
        header-align="center"
        align="center"
        label="采购类型">
      </el-table-column>
      <el-table-column
        prop="contItem"
        header-align="center"
        align="center"
        label="合同标的物">
      </el-table-column>
      <el-table-column
        prop="money"
        header-align="center"
        align="center"
        label="币别">
      </el-table-column>
      <el-table-column
        prop="taxRate"
        header-align="center"
        align="center"
        label="税率">
      </el-table-column>
      <el-table-column
        prop="wrapBack"
        header-align="center"
        align="center"
        label="包装物是否回收">
      </el-table-column>
      <el-table-column
        prop="verifyStand"
        header-align="center"
        align="center"
        label="验收标准">
      </el-table-column>
      <el-table-column
        prop="mode"
        header-align="center"
        align="center"
        label="运输方式">
      </el-table-column>
      <el-table-column
        prop="payCond"
        header-align="center"
        align="center"
        label="付款条件">
      </el-table-column>
      <el-table-column
        prop="verifyDate"
        header-align="center"
        align="center"
        label="验收时间">
      </el-table-column>
      <el-table-column
        prop="qualityStand"
        header-align="center"
        align="center"
        label="质量要求及技术标准">
      </el-table-column>
      <el-table-column
        prop="standardNo"
        header-align="center"
        align="center"
        label="标准号">
      </el-table-column>
      <el-table-column
        prop="place"
        header-align="center"
        align="center"
        label="交(提)货地点">
      </el-table-column>
      <el-table-column
        prop="contPrice"
        header-align="center"
        align="center"
        label="合同总金额(元)">
      </el-table-column>
      <el-table-column
        prop="transport"
        header-align="center"
        align="center"
        label="运输费用负担">
      </el-table-column>
      <el-table-column
        prop="payWay"
        header-align="center"
        align="center"
        label="付款方式">
      </el-table-column>
      <el-table-column
        prop="outPerm"
        header-align="center"
        align="center"
        label="逾期千分比">
      </el-table-column>
      <el-table-column
        prop="outDay"
        header-align="center"
        align="center"
        label="逾期天数">
      </el-table-column>
      <el-table-column
        prop="remark"
        header-align="center"
        align="center"
        label="备注">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './contract-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    mounted () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/purchase/contract/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then((data) => {
          if (data && data.code === 200) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/purchase/contract/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
